<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { px2vwh, px2vh, px2vw } from './utils/pxToVw'
import dayjs from 'dayjs'
import { useRoute } from 'vue-router'
const route = useRoute()
const timer = ref()
const weather = ref(null)
const currentTime = ref('')
const dayOfWeek = ref(new Date().toLocaleDateString('default', { weekday: 'long' }))
const formateDate = () => {
  currentTime.value = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
}
const isActive = (path) => {
  return route.path === path
}
onMounted(() => {
  //创建定时器1秒执行一次
  timer.value = setInterval(() => {
    formateDate()
  }, 1000)
})
//取消定时器
onBeforeUnmount(() => {
  clearInterval(timer.value) //清除定时器
})
</script>

<template>
  <div class="header">
    <div class="boxWidth">
      <div class="logo">
        <img src="./assets/img/logo.png" />
      </div>
    </div>
    <!-- <div class="text">数字化工厂大屏</div> -->
    <div class="boxWidth rightBox">
      <ul class="right">
        <li class="weatherIcon"></li>
        <li>多云 15-23℃</li>
        <li class="time">{{ currentTime }}</li>
        <li>{{ dayOfWeek }}</li>
      </ul>
    </div>
  </div>
  <div class="content">
    <RouterView />
  </div>
  <div class="navBar">
    <RouterLink :class="isActive('/') ? 'active' : ''" to="/">
      <span>工厂全局</span>
    </RouterLink>
    <RouterLink
      :class="isActive('/ProductionSituation') ? 'active' : ''"
      to="/ProductionSituation"
    >
      <span>生产态势</span>
    </RouterLink>
    <RouterLink :class="isActive('/Storage') ? 'active' : ''" to="/Storage"
      ><span>仓储态势</span></RouterLink
    >
    <RouterLink :class="isActive('/Facility') ? 'active' : ''" to="/Facility"
      ><span>设备运行</span></RouterLink
    >
  </div>
</template>

<style scoped lang="less">
.header {
  width: 100vw;
  height: 8.77vh;
  background: url(./assets/img/header.png) no-repeat;
  background-size: 100% 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 50px 10px 36px;
  .boxWidth {
    width: 30vw;
  }
  .rightBox {
    display: flex;
    justify-content: end;
  }
  .logo {
    width: 235px;
    height: 50px;
    display: flex;
    align-items: center;
    margin-top: -14px;
    img {
      max-width: 100%;
      max-height: 100%;
    }
  }
  .text {
    font-size: 37px;
    color: #ffffff;
    font-family: FZLanTingHei-L-GBK;
    font-weight: bold;
  }
  .right {
    display: flex;
    gap: 10px;
    color: #159dd7;
    font-size: 16px;
    align-items: center;
    margin-top: -10px;
    .time {
      margin: 4px 10px 0 30px;
      width: 170px;
    }
    .weatherIcon {
      width: 35px;
      height: 25px;
      background: url(./assets/img/weatherIcon.png) no-repeat;
      background-size: 100% 100%;
    }
  }
}
.content {
  width: 100vw;
  height: 91.23vh;
  padding: 15px 25px 38px 25px;
}
.navBar {
  position: fixed;
  width: 584px;
  height: 41px;
  left: calc(50% - 292px);
  bottom: 38px;
  color: #fff;
  display: flex;
  gap: 8px;
  a {
    width: 140px;
    font-size: 16px;
    align-items: center;
    text-align: center;
    background: url(./assets/img/button.png) no-repeat;
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .active {
    background: url(./assets/img/buttonActive.png) no-repeat;
    background-size: 100% 100%;
    color: #39f8ff;
  }
}
</style>
<style lang="less">
#app {
  background: url(./assets/img/bg.png) no-repeat;
  background-size: 100% 100%;
  background-color: #01080e;
}
</style>